package com.fr.privilege;

import com.fr.base.core.BaseCoreUtils;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.core.FRCoreContext;
import com.fr.base.core.RSADecode;
import com.fr.base.core.json.JSONObject;
import com.fr.base.core.util.vt.VT4FR;
import com.fr.base.core.util.vt.VT4FR.FUNC;
import com.fr.privilege.authority.Authority;
import com.fr.util.Consts;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

public abstract class AbstractPrivilege
  implements Privilege
{
  private static boolean authorityAvailable = true;
  private static final long serialVersionUID = -4406366638087696364L;
  private List authorityList = null;

  public Authority[] neededAuthority()
  {
    return (((!(authorityAvailable)) || (this.authorityList == null)) ? new Authority[0] : (Authority[])this.authorityList.toArray(new Authority[this.authorityList.size()]));
  }

  public void addAuthority(Authority paramAuthority)
  {
    if (this.authorityList == null)
      this.authorityList = new ArrayList(3);
    this.authorityList.add(paramAuthority);
  }

  public int getAuthorityCount()
  {
    return ((this.authorityList == null) ? 0 : this.authorityList.size());
  }

  public Authority getAuthority(int paramInt)
  {
    if ((paramInt < 0) || (paramInt >= getAuthorityCount()))
      return null;
    return ((Authority)this.authorityList.get(paramInt));
  }

  public void clearAuthority()
  {
    if (this.authorityList != null)
      this.authorityList.clear();
    this.authorityList = null;
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    AbstractPrivilege localAbstractPrivilege = (AbstractPrivilege)super.clone();
    localAbstractPrivilege.authorityList = null;
    int i = 0;
    int j = getAuthorityCount();
    while (i < j)
    {
      localAbstractPrivilege.addAuthority((Authority)getAuthority(i).clone());
      ++i;
    }
    return localAbstractPrivilege;
  }

  static
  {
    byte[] arrayOfByte = FRCoreContext.getBytes();
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    try
    {
      RSADecode.decode(arrayOfByte, localByteArrayOutputStream);
    }
    catch (Exception localException1)
    {
    }
    try
    {
      JSONObject localJSONObject = new JSONObject(new String(localByteArrayOutputStream.toByteArray(), "UTF-8"));
      authorityAvailable = (localJSONObject.getLong("deadline") > Calendar.getInstance().getTimeInMillis()) && (localJSONObject.has("version")) && (ComparatorUtils.equals(Consts.VERSION, localJSONObject.getString("version"))) && (((localJSONObject.getLong("deadline") - Calendar.getInstance().getTimeInMillis() < 3153600000L) || ((localJSONObject.has("macaddress")) && (BaseCoreUtils.getMacAddresses().contains(localJSONObject.getString("macaddress")))))) && (VT4FR.PRIVILIGE.support());
    }
    catch (Exception localException2)
    {
    }
  }
}